#include <iostream>
using namespace std;

class MySort
{
public:
    MySort(int size);
    void buble_sort();
    void insert_sort();
    void select_sort();
    void show();
    int size;
    unique_ptr<int[]> array;
};

MySort::MySort(int size):size(size){}
void MySort::show()
{
    for(int i = 0; i < size; i++){
        cout<<array[i]<<" ";
    }
    cout<<endl;
}

void MySort::buble_sort()
{
    int tmp;
    bool flag = false;
    for(int i = 0; i < size - 1; i++){
        flag = false;
        for(int j = 0; j < size - i - 1; j++){
            if (array[j] > array[j+1]){
                tmp = array[j];
                array[j] = array[j+1];
                array[j+1] = tmp;
                flag = true;
            }
        }
        if (!flag) break;
    }
}

void MySort::insert_sort()
{
    int tmp;
    for(int i = 1; i < size; i++){
        for(int j = i; j > 0; j--){
            if (array[j] < array[j-1]){
                tmp = array[j-1];
                array[j-1] = array[j];
                array[j] = tmp; 
            } else {
                break;
            }
        }
    }
}

void MySort::select_sort()
{
    int tmp;
    int index;
    int val;
    for(int i = 0; i < size-1; i++){
        int val = array[i];
        index = i;
        for(int j = i+1; j < size; j++){
            if (array[j] < val){
                val = array[j];
                index = j;
            }
        }
        if (index != i){
            tmp = array[i];
            array[i] = array[index];
            array[index] = tmp;
        }
    }
}

int main()
{
    int size = 10;
    std::unique_ptr<int[]> p = std::make_unique<int[]>(size);
    p[0] = 0;
    p[1] = 2;
    p[2] = 1;
    p[3] = 4;
    p[4] = 6;
    p[5] = 5;
    p[6] = 7;
    p[7] = 10;
    p[8] = 11;
    p[9] = 3;
    MySort mysort(10);
    mysort.array = std::move(p);
    mysort.show();
    //mysort.buble_sort();
    //mysort.insert_sort();
    mysort.select_sort();
    mysort.show();
}